/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __M_PAGE_H__
#define __M_PAGE_H__

/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_rbtree.h>
#include <x_list.h>

#include <k_mutex.h>
/* includes (local) ----------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/

typedef struct page_node {
    uint32_t pfn;
    uint32_t pages;
    rb_node_t pfn_node;
    rb_node_t siz_node;
} page_node_t;

typedef struct page_pool {
    rb_tree_t pfn_tree;
    rb_tree_t siz_tree;
    mutex_t mutex;
} page_pool_t;

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern int page_pool_init(page_pool_t *pool);
extern int page_pool_put(page_pool_t *pool, uint32_t pfn, uint32_t pages);
extern int page_pool_get(page_pool_t *pool, uint32_t pages, uint32_t *pfn);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __M_PAGE_H__ */
